package com.gukun.springboot.tdengine.enums;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

public enum DataDeleteType {
    /**
     * 一个月内数据
     */
    ONE_MONTH,
    THREE_MONTH,
    SIX_MONTH,
    /**
     * 一年内数据
     */
    ONE_YEAR,
    TWO_YEAR,
    /**
     * 三年内数据
     */
    THREE_YEAR,
    /**
     * 五年内数据
     */
    FIVE_YEAR,
    /**
     * 10年内数据，永久
     */
    FOREVER;

    public static long getTimestamp(String dataDeleteTypeStr) {
        Date date = new Date();
        DataDeleteType dataDeleteType = DataDeleteType.valueOf(dataDeleteTypeStr);
        return switch (dataDeleteType) {
            case ONE_MONTH -> DateUtil.offset(date, DateField.MONTH, -1).getTime();
            case THREE_MONTH -> DateUtil.offset(date, DateField.MONTH, -3).getTime();
            case SIX_MONTH -> DateUtil.offset(date, DateField.MONTH, -6).getTime();
            case ONE_YEAR -> DateUtil.offset(date, DateField.YEAR, -1).getTime();
            case TWO_YEAR -> DateUtil.offset(date, DateField.YEAR, -2).getTime();
            case THREE_YEAR -> DateUtil.offset(date, DateField.YEAR, -3).getTime();
            case FIVE_YEAR -> DateUtil.offset(date, DateField.YEAR, -5).getTime();
            default -> 0;
        };
    }
}
